package com.woniu.controller;

import com.woniu.entity.SecKillBook;
import com.woniu.entity.dto.SecBookDTO;
import com.woniu.entity.vo.SecActiveVo;
import com.woniu.service.SecKillBookService;
import com.woniu.util.ResData;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/seckill")
public class SeckillBookController {

    @Autowired
    private SecKillBookService secKillBookService;

    @PostMapping("/addKillBook")
    public ResData<?> addKillBook(@RequestBody SecKillBook secKillBook){
        return secKillBookService.addKillBook(secKillBook);
    }

    @GetMapping("/queryDetail")
    public ResData<?> queryDetail(Integer bookId){
        return secKillBookService.queryDetail(bookId);
    }

    @GetMapping("/queryAll")
    public ResData<?> queryAll(){
        return secKillBookService.queryAll();
    }

    @GetMapping("/startKill/{bookId}")
    public ResData<?> startKill(@PathVariable("bookId") Integer bookId, HttpServletRequest request){
        String token = request.getHeader("token");
        return secKillBookService.startKill(bookId,token);
    }

    @PostMapping("/addActive")
    public ResData<?> addActive(@RequestBody SecActiveVo secActive,HttpServletRequest request){//, SecActiveVo secActive){
        String token = request.getHeader("token");
        return secKillBookService.addActive(secActive,token);
    }
}
